package com.example.rotateimageview

import android.app.Application
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor

/**
 * author  : Liushuai
 * time    : 2021/11/6 8:57
 * desc    :
 */
class MyApplication : Application() {
    companion object {
        lateinit var instance: MyApplication
        fun getContext(): MyApplication {
            return instance
        }
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        initFlutterEngine()
    }

    //预热flutterEngine
    private fun initFlutterEngine() {
        val flutterEngine = FlutterEngine(this)
        flutterEngine.navigationChannel.setInitialRoute("myflutter/demo");
        // Start executing Dart code in the FlutterEngine.
        flutterEngine.dartExecutor.executeDartEntrypoint(
            DartExecutor.DartEntrypoint.createDefault())
       // Cache the pre-warmed FlutterEngine to be used later by FlutterFragment.
        FlutterEngineCache
            .getInstance()
            .put("my_engine_id", flutterEngine)
    }
}